/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.h
  * @brief          : Header for main.c file.
  *                   This file contains the common defines of the application.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2025 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
#include <string.h>
/* USER CODE END Includes */

/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */

/* USER CODE END ET */

/* Exported constants --------------------------------------------------------*/
/* USER CODE BEGIN EC */

/* USER CODE END EC */

/* Exported macro ------------------------------------------------------------*/
/* USER CODE BEGIN EM */

/* USER CODE END EM */

/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);

/* USER CODE BEGIN EFP */

/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/

/* USER CODE BEGIN Private defines */
#define U1BUFFER_SIZE                   128
#define U2BUFFER_SIZE                   256
#define PRINTF_DMA_BUF_SIZE             256

extern char DMAprintBuf[PRINTF_DMA_BUF_SIZE];
extern volatile uint8_t printOverFlag;

extern uint8_t u1RecFlag;
extern uint8_t u2RecFlag;

extern char u1RecBuf[U1BUFFER_SIZE];
extern uint8_t u2SendBuf[U2BUFFER_SIZE];
extern uint8_t u2RecBuf[U2BUFFER_SIZE];

extern SPI_HandleTypeDef hspi1;
extern SPI_HandleTypeDef hspi2;
extern UART_HandleTypeDef huart1;
extern UART_HandleTypeDef huart2;
extern ADC_HandleTypeDef hadc1;
extern DMA_HandleTypeDef hdma_usart1_rx;
extern DMA_HandleTypeDef hdma_usart1_tx;
extern DMA_HandleTypeDef hdma_usart2_tx;
extern DMA_HandleTypeDef hdma_usart2_rx;

extern struct ch8001Stu myCh;
extern struct ws2812Stu myWs;
extern struct rc522Stu myRc;
extern struct jdy25mStu myJdy;
extern struct koroCardStu myKoro;
extern struct koroAnimeStu koroAnime;

#define PRINT_LOG           "# "
#define PRINT_WARNNING      "W "
#define PRINT_ERROR         "E "
#define PRINT_DEBUG         "D "

#define printf_DMA(args...)             do{\
                                            while(printOverFlag);\
                                            printOverFlag = 1;\
                                            sprintf(DMAprintBuf, ##args); /* realTicks */\
                                            HAL_UART_Transmit_DMA(&huart1, (uint8_t *)DMAprintBuf, strlen(DMAprintBuf));\
                                        }while(0)
      
/* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
